home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / CTYPES.H < prev    next >
C/C++ Source or Header  |  1987-03-04  |  2KB  |  46 lines

  1. /*  File   : ctypes.h
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 26 April 1984
  4.     Purpose: Reimplement the UNIX ctype(3) library.
  5.  
  6.     isaneol(c) means that c is a line terminating character.
  7.     isalnum, ispunct, isspace, and isaneol are defined on the
  8.     range -1..127, i.e. on ASCII U {EOF}, while all the other
  9.     macros are defined for any integer.
  10.  
  11.     isodigit(c) checks for Octal digits.
  12.     isxdigit(c) checkx for heXadecimal digits.
  13. */
  14.  
  15. #define isdigit(c)     ((unsigned)((c)-'0') < 10)
  16. #define islower(c)     ((unsigned)((c)-'a') < 26)
  17. #define isupper(c)     ((unsigned)((c)-'A') < 26)
  18. #define isprint(c)     ((unsigned)((c)-' ') < 95)
  19. #define iscntrl(c)     ((unsigned)((c)-' ') >= 95)
  20. #define isascii(c)     ((unsigned)(c) < 128)
  21. #define isalpha(c)     ((unsigned)(((c)|32)-'a') < 26)
  22.  
  23. extern char    _c2type[];
  24.  
  25. #define isalnum(c)     (_c2type[(c)+1] < 36)
  26. #define ispunct(c)     (_c2type[(c)+1] == 36)
  27. #define isspace(c)     (_c2type[(c)+1] > 37)
  28. #define isaneol(c)     (_c2type[(c)+1] > 38)
  29.  
  30. #define        isxdigit(c)     (_c2type[(c)+1] < 16)
  31. #define isodigit(c)    ((unsigned)((c)-'0') < 8)
  32.  
  33. /*  The following "conversion" macros have been in some versions of UNIX
  34.     but are not in all.  tocntrl is new.  The original motivation for ^?
  35.     being a name for DEL was that (x)^64 mapped A..Z to ^A..^Z and also
  36.     ? to DEL.  The trouble is that this trick doesn't work for lower case
  37.     letters.  The version given here is not mine.  I wish it was.  It has
  38.     the nice property that DEL is mapped to itself (so does EOF).
  39.     tolower(c) and toupper(c) are only defined when isalpha(c).
  40. */
  41. #define        tolower(c)      ((c)|32)
  42. #define toupper(c)     ((c)&~32)
  43. #define tocntrl(c)     (((((c)+1)&~96)-1)&127)
  44. #define        toascii(c)      ((c)&127)
  45.  
  46.